<extend name="Base/common"/>

<block name="style">
    <style type="text/css">
        .nav-pills{
            border-bottom: 1px solid #d3d1e5;
        }
        .nav-pills>li>a{
            border-radius: 0px;
        }
        .nav-pills>li.active>a, 
        .nav-pills>li.active>a:focus, 
        .nav-pills>li.active>a:hover{
            background-color: #fff;
            color: #8084e7;
            border-bottom: 2px solid #8084e7;
        }
    </style>
</block>

<block name="body">
    <div id="page-wrapper" style="padding-left: 20px;padding-right: 20px;">
        <div class="col-md-12 col-sm-12" style="padding-left: 0px;padding-right: 0px;">
                    <div class="panel panel-default">
                        <ul class="nav nav-pills">
                                <li class="active"><a href="#home-pills" data-toggle="tab">竞价中</a>
                                </li>
                                <li class=""><a href="#profile-pills" data-toggle="tab">竞价结束</a>
                                </li>
                         </ul>
                        <div class="panel-body">
                             <form role="form" id="search_form">
                                    <div class="form-group col-md-2">
                                        <label for="start_time">创建起始时间</label>
                                        <input type="text" class="form-control" id="start_time" name="start_time" placeholder="选择开始时间">
                                    </div>
                                    <div class="form-group col-md-2">
                                        <label for="end_time">创建结束时间</label>
                                        <input type="email" class="form-control" id="end_time" name="end_time" placeholder="选择结束时间">
                                    </div>
                                    <div class="form-group col-md-2">
                                        <label for="cate_id">竞价类型</label>
                                        <select class="form-control" id="cate_id" name="cate_id">
                                          <option value="{$vo.id}">请选择</option>
                                          <volist name="cateList" id="vo">
                                             <option value="{$vo.id}">{$vo.name}</option>
                                          </volist>
                                        </select>
                                    </div>
                                    <div class="form-group col-md-2">
                                        <label for="bid_sn">竞价单号</label>
                                        <input type="text" id="bid_sn" name="bid_sn" class="form-control" id="exampleInputEmail1">
                                    </div>
                                    <div class="form-group col-md-2"></div>
                                    <div class="form-group col-md-1">
                                        <label for="bid_search" style="opacity: 0;">1</label>
                                        <button type="button" id="bid_search" class="btn btn-default form-control" style="background:#8084e7!important;color: #fff;border: 0;">查询</button>
                                    </div>
                                    <div class="form-group col-md-1">
                                        <label for="refresh" style="opacity: 0">1</label>
                                        <button type="button" id="refresh" class="btn btn-default form-control">重置</button>
                                    </div>
                             </form>
                        </div>

                        <div class="panel-body" style="padding:0px;">

                            <div class="tab-content">

                                <div class="tab-pane fade active in" id="home-pills" data-action="{:U('ajaxPostBidList',array('is_end'=>0))}">
                                       <div class="table-responsive">
                                        <table class="table table-hover" id="dataTables-example" style="border: 1px solid #ddd;margin-bottom: 0px;">
                                          <thead>
                                              <tr class="active w_table_tr1">
                                                  <td style="width: 12%">创建时间</td>
                                                  <td style="width: 13%">竞价单号</td>
                                                  <td style="width: 15%">竞价单名称</td>
                                                  <td style="width: 12%">竞价单类型</td>
                                                  <td style="width: 15%">截止时间（倒计时）</td>
                                                  <td style="width: 15%">已报价数（金额）</td>
                                                  <td style="width: 8%">操作</td>
                                              </tr>
                                          </thead>
                                          <tbody>
                                           <notempty name="list"> 
                                             <volist name="list" id="vo">
                                               <php>
                                                   $cate_type=M('bid_type')->where(array('id'=> $vo['cate_id']))->getField('name');
                                                   $user_count=M('bid_user')->where(array('bid_id'=>$vo['id']))->field('count(*) as user_count,sum(user_price) as price_count')->find();
                                               </php>

                                               <tr class="odd gradeX">
                                                  <td>{$vo.start_time|time_format='Y-m-d H:i:s'}</td>
                                                  <td>{$vo.bid_sn}</td>
                                                  <td>{$vo.name}</td>
                                                  <td class="center">{$cateList[$vo['cate_id']]['name']}
                                                  </td>
                                                  <td class="center">{$vo.end_time|time_format='Y-m-d H:i:s'}</td>
                                                  <td>{$user_count.user_count}({$user_count.price_count})</td>
                                                  <td style="width: 8%" class="w_table_a1">
                                                    <a href="{:U('bidding_info',array('id'=>$vo['id']))}" target="_blank">详情</a></a>
                                                  </td>
                                              </tr>
                                             </volist>  
                                            <else/>
                                              <tr><td colspan="7" class="text-center">暂时还没有竞价信息!</td>
                                              </tr>
                                            </notempty>                    
                                          </tbody>  
                                     </table>
                        
                            
                                   </div>
                                </div>


                                <div class="tab-pane fade" id="profile-pills" data-action="{:U('ajaxPostBidList',array('is_end'=>1))}">
                                    <div class="table-responsive">
                                        <table class="table table-hover" id="dataTables-example-end"  style="border: 1px solid #ddd;margin-bottom: 0px;">
                                          <thead>
                                              <tr class="active w_table_tr1">
                                                  <td style="width: 12%">创建时间</td>
                                                  <td style="width: 13%">竞价单号</td>
                                                  <td style="width: 15%">竞价单名称</td>
                                                  <td style="width: 12%">竞价单类型</td>
                                                  <td style="width: 15%">已报价数</td>
                                                  <td style="width: 15%">竞拍成功数(金额)</td>
                                                  <td style="width: 8%">操作</td>
                                              </tr>
                                          </thead>
                                          <tbody>
                                           <notempty name="list_end"> 
                                            <volist name="list_end" id="vo">
                                                <php>
                                                    $cate_type=M('bid_type')->where(array('id'=> $vo['cate_id']))->getField('name');
                                                    switch ($vo['cate_id']) {
                                                         case '1':
                                                         $user_list=M('bid_user')->where(array('bid_id'=>$vo['id']))->order('user_price desc')->select();
                                                         $bid_count=count($user_list);
                                                         $bid_success=1;
                                                         $bid_price=$user_list[0]['user_price'];
                                                         break;

                                                         case '2':

                                                          $user_list=M('bid_user')->where(array('bid_id'=>$vo['id']))->select();
                                                          $bid_count=count($user_list);

                                                          $my_bids=M('bid_user')->where(array('bid_id'=>$vo['id'],'user_id'=>is_login()))->select();
                                                          $my_bids=get_id_key($my_bids,'good_id');
                                                          $bid_success=0;
                                                          $bid_price=0;
                                                           foreach ($my_bids as $k=>&$v){
                                                              $map['bid_id']=$vo['id'];
                                                              $map['user_price']=array('gt',$v['user_price']);
                                                              $map['good_id']=$v['good_id'];
                                                              //获取单个商品报价高于我的人数
                                                              $item_count=M('bid_user')->where($map)->count();
                                                              if($item_count==0){
                                                                $bid_success+=$v['user_number'];
                                                                $bid_price+=$v['user_price'];
                                                             }
                                                          }

                                                         break;
                                                    }

                                                </php>
                                              <tr class="odd gradeX">
                                                  <td>{$vo.start_time|time_format='Y-m-d H:i:s'}</td>
                                                  <td>{$vo.bid_sn}</td>
                                                  <td>{$vo.name}</td>
                                                  <td class="center">{$cateList[$vo['cate_id']]['name']}
                                                  </td>
                                                  <td class="center">{$bid_count}</td>
                                                  <td>{$bid_success}({$bid_price})</td>
                                                  <td style="width: 8%" class="w_table_a1">
                                                    <a href="{:U('bidding_end',array('id'=>$vo['id']))}" target="_blank">详情</a></a>
                                                  </td>
                                              </tr>
                                             </volist>   
                                             <else/>
                                              <tr><td colspan="7" class="text-center"> aOh!  暂时还没有信息! </td>
                                              </tr>
                                            </notempty>                   
                                          </tbody>  
                                     </table>
                        
                            
                                   </div>
                                </div>
                           
                             
                            </div>
                        </div>
                    </div>
                </div>
        <!-- /. PAGE INNER  -->
    </div>
</block>
<block name="script">
<script src="__STATIC__/layui/layui/layui.js"></script>
    <script type="text/javascript">
        layui.use('laydate', function(){
          var laydate = layui.laydate;
  
        //执行一个laydate实例
           laydate.render({
              elem: '#start_time' //指定元素
              ,type: 'datetime'
              ,format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
          });

          laydate.render({
              elem: '#end_time' //指定元素
              ,type: 'datetime'
              ,format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
          }); 
       });
 </script>
</block>